<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <s-table
        ref="table"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :scroll="{x:true}"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <!-- 表格操作栏 -->
        <template slot="tabAction">
          <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
        </template>
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="date" slot-scope="text">{{ text | moment }}</span>
        <a-icon slot="ableCheck" slot-scope="text" :type=" text ? 'check-circle' : 'close-circle'" class="fz-18" :class=" text ? 'text-success' : 'text-error'"/>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleEdit(record)">修改</a>
          </template>
        </span>
      </s-table>
    </a-card>
    <app-form :visible.sync="visibleForm" :propsData="propsData" @success="handleRefresh"></app-form>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import AppForm from './form'
import { getUpdateAppPagingList } from '@/api/application'
const columns = [
  {
    title: '序号',
    align: 'center',
    width: 80,
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: 'AppID',
    align: 'center',
    dataIndex: 'appid'
  },
  {
    title: '应用名称',
    align: 'center',
    dataIndex: 'name'
  },
  {
    title: '更新标题',
    align: 'center',
    dataIndex: 'title'
  },
  {
    title: '更新平台',
    align: 'center',
    dataIndex: 'platformName'
  },
  {
    title: '安装包类型',
    align: 'center',
    dataIndex: 'typeName'
  },
  {
    title: '当前版本号',
    align: 'center',
    dataIndex: 'version'
  },
  {
    title: '下载地址',
    align: 'center',
    dataIndex: 'url'
  },
  {
    title: '是否上线发行',
    align: 'center',
    dataIndex: 'stable_publish',
    scopedSlots: { customRender: 'ableCheck' }
  },
  {
    title: '是否默认更新',
    align: 'center',
    dataIndex: 'is_silently',
    scopedSlots: { customRender: 'ableCheck' }
  },
  {
    title: '是否强制更新',
    align: 'center',
    dataIndex: 'is_mandatory',
    scopedSlots: { customRender: 'ableCheck' }
  },

  {
    title: '上传时间',
    align: 'center',
    dataIndex: 'create_date',
    scopedSlots: { customRender: 'date' }
  },
  {
    title: '操作',
    align: 'center',
    fixed: 'right',
    dataIndex: 'action',
    width: 150,
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'UserList',
  components: {
    STable,
    Ellipsis,
    AppForm
  },
  data () {
    this.columns = columns
    return {
      visibleForm: false,
      propsData: {},
      // 查询参数
      queryParam: {
        strContent: {},
        userid: this.$store.getters.userid
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getUpdateAppPagingList(requestParameters).then(res => {
          return res
        })
      }
    }
  },
  methods: {
    handleRefresh (refresh) {
      this.$refs.table.refresh(refresh)
    },
    handleAdd () {
      this.visibleForm = true
      this.propsData = {}
    },
    handleEdit (record) {
      this.visibleForm = true
      this.propsData = record
    }
  }
}
</script>
